<?php
require_once('mysql_connect.php');
if (!isset($_SESSION['userid'])){
	header("Location:login.php");
	exit();
}

$loc ="search";

$search = escape_data($_POST['search']);
$search = trim($search);
if (strlen($search) > 0){
    $searcha = explode(' ', $search);
    $search = implode('%\' AND CONCAT(name, \' \', description) LIKE \'%', $searcha);
    $search = "'%" . $search . "%'";
    $query = "SELECT * FROM movie WHERE CONCAT(name, ' ', description) LIKE " .  $search .  " ORDER BY name";
    $result = @mysql_query($query);

    $querytwo = "SELECT * FROM movie WHERE rating='" . strtolower(escape_data($_POST['search'])) . "' ORDER BY name";
    $resulttwo = @mysql_query($querytwo);
    $search = implode('%\' AND name LIKE \'%', $searcha);
    $search = "'%" . $search . "%'";

    $querythree = "SELECT * FROM actor WHERE name LIKE " . $search . " ORDER BY name";
    $resultthree = @mysql_query($querythree);
	$search = implode('%\' AND name LIKE \'%', $searcha);
    $search = "'%" . $search . "%'";
	$queryfour = "SELECT * FROM genre WHERE name LIKE " . $search . " ORDER BY name";
    $resultfour = @mysql_query($queryfour);

}
include('top.php');
?>
<TABLE><TR><TD>
<?php
if(@mysql_num_rows($resultthree) > 0){
?>	
	<BR><FONT FACE="Verdana" size="4">Actors:</FONT><UL>
	<?php
	while($actorrow = mysql_fetch_array($resultthree)){
	?>
	<FONT FACE="Verdana" size="-1"><LI></FONT><A HREF="viewactor.php?id=<?php echo $actorrow['id'];?>"><FONT FACE="Verdana" size=-1 color=000000><?php echo $actorrow['name'];?></FONT></A>
	<?php
	}
	?>
	</UL><BR><HR WIDTH="100%">
<?php
}
?>
<?php
if(@mysql_num_rows($resultfour) > 0){
?>	
	<BR><FONT FACE="Verdana" size="4">Genres:</FONT><UL>
	<?php
	while($actorrow = mysql_fetch_array($resultfour)){
	?>
	<FONT FACE="Verdana" size="-1"><LI></FONT><A HREF="viewgenre.php?id=<?php echo $actorrow['id'];?>"><FONT FACE="Verdana" size=-1 color=000000><?php echo $actorrow['name'];?></FONT></A>
	<?php
	}
	?>
	</UL><BR><HR WIDTH="100%">
<?php
}
?>
<?php
if(@mysql_num_rows($resulttwo) > 0){
?>	
	<BR><FONT FACE="Verdana" size="4">Movies with that rating:</FONT><BR><BR>
	<?php
	while($actorrow = mysql_fetch_array($resulttwo)){
	echo showmovie($actorrow['id']);	
	}
	?>
	<BR><HR WIDTH="100%">
<?php
}
?>
<?php
if(@mysql_num_rows($result) > 0){
?>	
<?php
	while($actorrow = mysql_fetch_array($result)){
	echo showmovie($actorrow['id']);	
	}
	?>
	<BR><HR WIDTH="100%">
<?php
}
?>


</TD></TR></TABLE>
<?php
include('bot.php');
?>